package com.weijianhuawen.wjblog.admin.config;

import io.swagger.annotations.Api;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description: 后台文档生成
 * @date: 2024-10-15 18:02
 */
@Configuration
@EnableSwagger2WebMvc
@Profile("dev")
public class Knife4jAdminConfig {
    @Bean("adminApi")
    public Docket createAdminDoc() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(buildApiInfo())
                .groupName("博客平台后台接口")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.weijianhuawen.wjblog.admin"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 构建api文档基本信息
     * @return apiINFO
     */
    private ApiInfo buildApiInfo() {
        return new ApiInfoBuilder()
                .title("WJBlog博客平台后台文档接口")
                .description("博客后台管理")
                .termsOfServiceUrl("weijianhuawen.com")
                .contact(new Contact("未见花闻", "https://weijianhuawn.com", "weijianhuawen@163.com"))
                .version("1.0.0")
                .build();
    }
}
